package LeetCode.NumOffer;

/**
 * 礼物的最大价值
 * @author lumin
 * @date 2022/04/12 14:37
 **/
public class NumOffer47 {
    public int maxValue(int[][] grid) {
        int i = 0;
        while(i < grid.length){
            int j = 0;
            while(j < grid[0].length){
                if(i == 0){
                    if(j == 0){
                        grid[i][j] = grid[i][j];
                    }else{
                        grid[i][j] = grid[i][j] + grid[i][j - 1];
                    }
                }else{
                    if(j == 0){
                        grid[i][j] = grid[i][j] + grid[i - 1][j];
                    }else{
                        grid[i][j] = grid[i][j] + Math.max(grid[i - 1][j],grid[i][j - 1]);
                    }
                }
                j++;
            }
            i++;
        }
        return grid[grid.length - 1][grid[0].length - 1];
    }
}